﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using Testing.Cons.ole;
using System.Reflection;

namespace Testing.Cons
{
    class Program
    {
        static void Main(string[] args)
        {
            //Binder http://www.codeproject.com/KB/grid/TableBindHelper.aspx

            //Mas interesante http://fredmastro.com/post/Mapping-a-DataTable-to-an-Object-Class-Like-a-homemade-Linq-to-SQL-Send-over-WCF-to-SilverLight.aspx

            //new Pings().MakePing("74.125.157.104");


           // Console.WriteLine(Resource1.ResourceManager.GetObject("Test").ToString());
            
            //CryptoStreamTest cst = new CryptoStreamTest();
            ////cst.Encrypt();
            ////cst.Decrypt();

            ////List<Auto> autos = GetAutos();
            ////List<Auto> autos2 = GetAutos();


            ////Console.WriteLine("---");

            ////List<Auto> res = autos.Where(x => x.Anio == 555 || x.Anio == 111).ToList();
            ////res.ForEach(x => Console.WriteLine(x.GetDatos()));

            //ClasePrueba cp = new ClasePrueba("iwfnewu");
            //infoTipo(cp.GetType());
            ////GetAttribute(typeof(ClasePrueba));

            //Console.WriteLine("Test: {0}", cp.CampoPublico1.GetType().Name);


            //script
            //=CONCATENATE("SELECT * FROM [Placemark] where [Description] = '", B3, "'"," OR", " [Description] = '", B4, "' OR", " [Description] = '")


            string queryBase = "=CONCATENATE(\"SELECT * FROM [Placemark] where";
            string queryClause = " [Description] = '\", B{0}, \"'";
            string or = "\",\" OR\", \"";
            int i = 3;
            string query = queryBase + string.Format(queryClause, i.ToString());

            string test2 = "=CONCATENATE(\"SELECT * FROM [Placemark] where "
                        + "[Description] = '\", B3, \"'\",\" OR\", \" "
                        + "[Description] = '\", B4, \"'\",\" OR\", \" "
                        + "[Description] = '\", B5)";

            for (i = 4; i <= 1260; i++)
            {
                query += or + string.Format(queryClause, i.ToString());
            }
            query += "\")";

            Console.WriteLine(query);
            Console.WriteLine(test2);

            Console.WriteLine(test2 == query);

            Console.WriteLine("\nTecla...");
            Console.ReadKey(true);
        }

        private static List<Auto> GetAutos()
        {
            if (!Cache.IsCached(new List<Auto>()))
            {
                Auto autoMio = new Auto();
                autoMio.Anio = 555;
                autoMio.Marca = "Ignacio";
                autoMio.Patente = (555).ToString();

                Auto autoTuyo = new Auto();
                autoTuyo.Anio = 111;
                autoTuyo.Marca = "Cristian";
                autoTuyo.Patente = (111).ToString();

                List<Auto> autos = new List<Auto>();

                autos.Add(autoMio);
                autos.Add(autoTuyo);

                Cache.Add(autos);
            }

            return Cache.Get(new List<Auto>());
        }


        //http://msdn.microsoft.com/en-us/library/71s1zwct.aspx
        public static void GetAttribute(Type t)
        {
            // Get instance of the attribute.
            SerializableAttribute MyAttribute =
                (SerializableAttribute)Attribute.GetCustomAttribute(t, typeof(SerializableAttribute));

            if (MyAttribute == null)
            {
                Console.WriteLine("The attribute was not found.");
            }
            else
            {
                // Get the Name value.
                Console.WriteLine("The Name Attribute is: {0}.", MyAttribute);
                // Get the Level value.
                Console.WriteLine("The Level Attribute is: {0}.", MyAttribute.TypeId);
                // Get the Reviewed value.
                Console.WriteLine("The Reviewed Attribute is: {0}.", MyAttribute);
            }
        }

        private static void infoTipo(Type  t)
        {
            BindingFlags flags  = BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.DeclaredOnly
                | BindingFlags.Static;
            string s  = String.Format("Los miembros públicos de: {0}", t.Name);
            Console.WriteLine(s);
            Console.WriteLine(new string('=', s.Length));
            //
            Console.WriteLine("Los campos");
            FieldInfo[] cs  = t.GetFields(flags);
            foreach(FieldInfo m in cs)
            {
                Console.WriteLine("   {0}", m.Name);
            }
            Console.WriteLine();
            //
            Console.WriteLine("Los métodos");
            MethodInfo[] mi  = t.GetMethods(flags);
            foreach(MethodInfo m in mi)
            {
                // no mostrar los que tienen nombres especiales
                // por ejemplo, las propiedades tendrán dos métodos asociados:
                // get_NombrePropiedad y set_NomprePropiedad
                if( m.IsSpecialName == false )
                {
                    Console.WriteLine("   {0}", m.Name);
                }
            }
            Console.WriteLine();
            //
            Console.WriteLine("Las propiedades");
            PropertyInfo[] pr  = t.GetProperties(flags);
            foreach(PropertyInfo m in pr)
            {
                Console.WriteLine("   {0}", m.Name);
            }
            Console.WriteLine();
            //
            Console.WriteLine("Los eventos");
            EventInfo[] evs  = t.GetEvents(flags);
            foreach(EventInfo m in evs)
            {
                Console.WriteLine("   {0}", m.Name);

            }


            Console.WriteLine();
        }

        //static void Main(string[] args)
        //{
        //    //GestorTXT gx = new GestorTXT();


        //    ////List<string> trucha = new List<string>();

        //    ////for (int j = 0; j < 11; j++)
        //    ////{
        //    ////    string str = "";
        //    ////    for (int i = 0; i < 10; i++)
        //    ////    {
        //    ////        int r = j + i;
        //    ////        str += (r >= 10 ? r >= 20 ? r >= 30 ? 1 : r - 20 : r - 10 : r).ToString();
        //    ////    }
        //    ////    trucha.Add(str);
        //    ////}

        //    ////gx.Crear(trucha);


        //    //List<string> myList = gx.Leer();

        //    //myList.ForEach(x => Console.WriteLine(x));



        //    //MyClass mc = new MyClass();

        //    //Calculate add = new Calculate(mc.add);
        //    //Calculate sub = new Calculate(mc.sub);

        //    //Console.WriteLine("Adding two values: " + add(10, 6));
        //    //Console.WriteLine("Subtracting two values: " + sub(10,4));
        //    string video1 = "No hay";

        //    string[] files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory());
        //   /*foreach (string file in files)
        //    {
        //        var i = file.Split('\\').Last();
        //        if(i.Split('.').Last() == "exe")
        //            video1 = i;
        //    }
        //    Console.WriteLine(video1);*/

        //    /*foreach (string file in files)
        //    {
        //        var i = file.Split('\\').Last();
        //        if (i == "Video1.wmv")
        //        {                    
        //            video1 = i;
        //        }
        //    }
        //    Console.WriteLine(video1);*/
        //    string i;
        //    i = Directory.GetCurrentDirectory();
        //    i += "\\video1.wmv";
        //    Console.WriteLine(i);




        //    Console.WriteLine("\nTecla...");
        //    Console.ReadKey(true);


        //}
    }

    public delegate int Calculate(int value1, int value2);

    public class MyClass
    {
        public int add(int value1, int value2)
        {
            return value1 + value2;
        }

        public int sub(int value1, int value2)
        {
            return value1 - value2;
        }
    }
}
